# Author: Mr.Xu
# @Time : 2019/12/5 23:31
from alipay import AliPay

from . import settings
from settings import const

# 支付宝支付接口
alipay = AliPay(
    appid = settings.APPID,
    app_notify_url = None,  # 该通知接口一般都设置为None
    # 应用私钥
    app_private_key_string = settings.APP_PRIVATE_KEY_STRING,
    # 支付宝公钥（需要通过你的应用公钥去换阿里公钥）
    alipay_public_key_string = settings.ALIPAY_PUBLIC_KEY_STRING,
    # 签名算法
    sign_type = settings.SIGN_TYPE,  # RSA or RSA2
    # 测试环境，debug=False就是
    debug = settings.DEBUG  # False by default
)


def get_pay_url(out_trade_no, total_amount, subject):
    # 订单信息
    order_string = alipay.api_alipay_trade_page_pay(
        # 订单信息
        out_trade_no = out_trade_no,
        # 总价
        total_amount = total_amount,
        # 商品名
        subject = subject,
        # 同步回调的前台接口
        return_url = const.RETURN_URL,
        # 异步回调的后台接口
        notify_url = const.NOTIFY_URL
    )
    return order_string


